package com.mf.pte.pojo;

import com.mf.pte.utils.StringUtil;
import lombok.Data;

import java.util.ArrayList;

@Data
public class Item {

    private Solid component;
    private ArrayList<Item> children ;
    private int count;
    private boolean isUsed;

    public Item(Solid component,int count){
        this.component = component;
        this.count = count;
        this.children = new ArrayList<>();
    }

    public void addChild(Item child){
        children.add(child);
    }

    public void print(int level){
        System.out.println(StringUtil.getXTable(level)
                .append(component.toString()).append("count:").append(count));
        if(!isUsed){
            for(Item child :children){
                child.print(level+1);
            }
        }
    }

    public boolean isAsm(){
        return children.size() != 0;
    }

    public boolean isUsed(){return isUsed;}

    public void used(){ this.isUsed = true;}

    public void useItsChildren(){
        for (Item child : children) {
            child.used();
        }
    }

    public void restoreUsedState(){
        setUsed(false);
        for(Item child :children){
            child.restoreUsedState();
        }
    }
}
